import Vue from 'vue'
import Router from 'vue-router'
// 引入常量路由,异步路由,任意路由
import { constantRoutes, allAsyncRoutes, anyRoutes } from './routes'

// 使用vue-router插件
Vue.use(Router)

// 创建路由器实例
const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // 重置路由
}

// 对外暴露路由器
export default router
